<template>
	<view class="" style="position: relative;height: 100vh;">

		<view class="container" style="padding: 24rpx;box-sizing: border-box;background-color: #FFFFFF;
		height: 90vh;">

			<view
				style="margin-bottom: 32rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">
					<span style="color:red">*</span>
					姓名</text>
				<input type="text" v-model="realName"
					style="padding: 0 32rpx;border-radius: 8rpx;width: 100%;height: 92rpx;border: 2rpx solid #E5E7EB;box-sizing: border-box;"
					placeholder-style="font-size:28rpx;color:#9CA3AF;" placeholder="请输入真实姓名">
			</view>


			<view
				style="margin-bottom: 32rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">身份证号</text>
				<input type="text" v-model="idCardNo"
					style="padding: 0 32rpx;border-radius: 8rpx;width: 100%;height: 92rpx;box-sizing: border-box;border: 2rpx solid #E5E7EB;"
					placeholder-style="font-size:28rpx;color:#9CA3AF;" placeholder="请输入身份证号">
			</view>


			<view
				style="margin-bottom: 32rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">银行卡号</text>
				<input type="text" v-model="bankCardNo"
					style="padding: 0 32rpx;border-radius: 8rpx;width: 100%;height: 92rpx;border: 2rpx solid #E5E7EB;box-sizing: border-box;"
					placeholder-style="font-size:28rpx;color:#9CA3AF;" placeholder="请输入银行卡号">
			</view>

			<view
				style="margin-bottom: 32rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">银行卡手机号</text>
				<input type="text" v-model="bankCardPhone"
					style="padding: 0 32rpx;border-radius: 8rpx;width: 100%;height: 92rpx;border: 2rpx solid #E5E7EB;box-sizing: border-box;"
					placeholder-style="font-size:28rpx;color:#9CA3AF;" placeholder="请输入手机号">
			</view>

			<view
				style="margin-bottom: 60rpx;width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
				<text style="font-size: 28rpx;color: #374151;margin-bottom: 6rpx;">身份证照片</text>
				<view class="" style="width: 100%;display: flex;justify-content: space-between;align-items: center;">
					<uploadImg placeHolderText="请上传人像面" imageType="id_card" limit="1" @uploadSuccess="uploadFrontSuccess"
						:initImgs="initFrontImgs"></uploadImg>
					<uploadImg placeHolderText="请上传国徽面" imageType="id_card" limit="1" @uploadSuccess="uploadBackSuccess"
						:initImgs="initBackImgs"></uploadImg>

				</view>
			</view>

			<view
			
				style="border-radius: 8rpx;height: 152rpx;background: rgba(78, 205, 196, 0.1);;width: 100%;display: flex;flex-direction: column;justify-content: space-evenly;align-items: flex-start;padding: 16rpx;box-sizing: border-box;">
				<view 	@click="toWaterMarker" class="" style="display: flex;justify-content: center;align-items: center;">
					<image src="../../static/img/mine/deng.jpg" style="width: 21rpx;height: 28rpx"></image>
					<text style="margin-left: 12rpx;color: #111827;font-size: 28rpx;">提升收益</text>
				</view>
				<text @click="toCombineImages" style="margin-left: 28rpx;color: #6B7280;font-size: 28rpx;">完善个人资料可额外获得 1% 的收益提升</text>
			</view>
		</view>

		<view class=""
			style="width: 100%;background-color: #F9FAFB;box-sizing: border-box;padding: 32rpx;height: 152rpx;display: flex;justify-content: space-evenly;align-items: center;position: absolute;bottom: 0;left: 0;">
			<view class="" @click="save"
				style="border-radius: 8rpx;width: 45%;height: 100%;background-color:  #FF4D4F;line-height: 152rpx;color: #FFFFFF;display: flex;justify-content: center;align-items: center">
				保存
			</view>
			<view class="" @click="back"
				style="border-radius: 8rpx;width: 45%;height: 100%;border: 1px solid #FF4D4F;line-height: 152rpx;display: flex;justify-content: center;align-items: center;color:#FF4D4F ;">
				取消
			</view>
		</view>

	</view>
</template>

<script>
	import uploadImg from "../../components/zhtx-uploadImg/zhtx-uploadImg.vue"
	import {
		mapState,
		mapMutations,
		mapGetters
	} from 'vuex';
	export default {
		components: {
			uploadImg
		},
		data() {
			return {
				realName: "",
				idCardNo: "",
				idCardFront: "",
				idCardBack: "",
				bankCardNo: "",
				bankCardPhone: "",


				initFrontImgs: [],
				initBackImgs: []

			};
		},
		computed: {
			...mapGetters(['inviteCode', 'uid']),


		},

		onLoad(e) {
			this.loadMyUserInfo();
		},
		methods: {


			//获取基本信息
			loadMyUserInfo() {
				let that = this;
				this.$pin.request('GET', '/users/profile', null,
					successData => {

						if (successData.code = that.$pin.code.success) {
							
							that.realName = successData.data.real_name;
							that.idCardNo = successData.data.id_card_no;
							
							that.initFrontImgs.push(successData.data.id_card_front) ;
							that.initBackImgs.push(successData.data.id_card_back) ;
							
							this.idCardBack = successData.data.id_card_back;
							this.idCardFront = successData.data.id_card_front;
							
							
							that.bankCardNo = successData.data.bank_card_no;
							that.bankCardPhone = successData.data.bank_card_phone;
						}




					},
					failData => {
						console.log(failData)
						uni.showToast({
							icon: 'none',
							title: '加载用户信息时出错'
						})
					}
				)
			},


			//提价基本信息
			save() {

				var uid = uni.getStorageSync("uid");
				
				var bodyParam = {
					bank_card_no: this.bankCardNo,
					bank_card_phone: this.bankCardPhone.trim().replace(/\s+/g, ''),
					id_card_back: this.idCardBack,
					id_card_front: this.idCardFront,
					id_card_no: this.idCardNo.trim().replace(/\s+/g, ''),
					real_name: this.realName
				
				}

				this.$pin.request('POST', `/auth/${uid}/profile`, bodyParam, successData => {
					console.log(successData)
					if (successData.code == 2000) {
						uni.showToast({
							title: '设置成功'
						})
						
						uni.navigateBack({})

					} else {
						uni.showToast({
							title: '设置失败',
							icon: 'none'
						})
					}
				}, failData => {
					console.log(failData)
					uni.showToast({
						title: '设置失败',
						icon: 'none'

					})
				})


			},

			back() {

				uni.navigateBack({})
			},



			uploadFrontSuccess(e) {
				var that = this;
				console.log("身份证正面照片" + e)
				that.idCardFront = e[0]


			},



			uploadBackSuccess(e) {
				var that = this;
				console.log("身份证反面照片" + e)
				that.idCardBack = e[0]

			},





			// handleChange1(e) {
			// 	console.log(e)
			// 	this.avatarUrl = e
			// 	// this.finishBtnClick()
			// },
			// uploadbjSuccess(e) {
			// 	this.bgUrl = e
			// },

			// 添加收货地址
			addMoreType() {

				uni.navigateTo({
					url: "../user/address/address"
				})

			},

			// 完成
			finishBtnClick() {

				// if(this.bgUrl.length==0||this.avatarUrl.length==0){

				// 	uni.showToast({
				// 		title:'请添加图片',
				// 		icon:'none'
				// 	})
				// 	return
				// }

				var data = {
					introduction: this.introduction, //简介
					mobile: this.mobile, //手机号
					name: this.name, //团长名称
					bgUrl: "", //北京图片
					avatarUrl: this.avatarUrl[0], //头像
				};


				this.$pin.request('POST', 'istore/groupcolonel/update', data, successData => {
					console.log(successData)
					if (successData.code == 0) {
						uni.showToast({
							title: '设置成功'
						})
						if (this.fromPage == 'publish') {
							uni.redirectTo({
								url: '../publish/publish'
							})
						}
					} else {
						uni.showToast({
							title: '设置失败',
							icon: 'none'
						})
					}
				}, failData => {
					console.log(failData)
					uni.showToast({
						title: '设置失败',
						icon: 'none'

					})
				})

			},
			toCombineImages(){
				uni.navigateTo({
					url:"/pages/demo/combineImages/combineImages"
				})
			},
			toWaterMarker(){
				uni.navigateTo({
					url:"/pages/demo/waterMarker/waterMarker"
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
		background: #ededed;
	}

	.container {
		padding: 20rpx;
		box-sizing: border-box;
		position: relative;


		.product-list {
			width: 100%;
			// padding: 0 2% 3vw 2%;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.product {
				padding: 20rpx;
				box-sizing: border-box;
				width: 100%;
				background-color: #fff;
				margin: 0 0 15upx 0;
				border-radius: $pin-border-radius;
				box-shadow: $pin-shadow;
				// height: 499rpx;
			}
		}
	}

	.s-add-list-btn-icon {
		font-size: 80rpx;
		height: 80rpx;
		line-height: 80rpx;
		margin-bottom: 20rpx;
		color: #999;
	}
</style>